package com.atguigu4.search_sort.exer2;

/**
 * ClassName: ArrayExoer02
 * Package: com.atguigu4.search_sort.exer2
 * Description:
 *

 案例1：线性查找

 定义数组：int[] arr1 = new int[]{34,54,3,2,65,7,34,5,76,34,67};
 查找元素5是否在上述数组中出现过？如果出现，输出对应的索引值。



 * @Author xiao_qi
 * @Create 2024/3/15 13:37
 * @Version 1.0
 */
public class ArrayExoer02 {
    public static void main(String[] args){

        int[] arr1 = new int[]{34,54,3,2,65,7,34,5,76,34,67};
        int target = 17;
        int i = 0;
        for ( i = 0; i < arr1.length; i++) {
            if(arr1[i] == target){
                System.out.println("找到目标为：" + target + "\t" + "下标为：" + i);
                break;
            }
        }
        if (i == arr1.length){
            System.out.println("没有找到");
        }
    }
}
